package com.example.testsharedpreferences;

import java.util.Set;
import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesHelper {

	public static SharedPreferences sharedPreferences = MainActivity.context
			.getSharedPreferences("preferences", 0);;
	public static SharedPreferences.Editor editor = sharedPreferences.edit();

	public static boolean putValue(String key, String stringValue) {
		editor.putString(key, stringValue);
		editor.commit();
		return true;
	}

	public static String getString(String key) {
		return sharedPreferences.getString(key, null);
	}

	public static boolean putValue(String key, boolean booleanValue) {
		editor.putBoolean(key, booleanValue);
		editor.commit();
		return true;
	}

	public static boolean getBoolean(String key) {
		return sharedPreferences.getBoolean(key, false);
	}

	public static boolean putValue(String key, float floatValue) {
		editor.putFloat(key, floatValue);
		editor.commit();
		return true;
	}

	public static float getFloat(String key) {
		return sharedPreferences.getFloat(key, -1);
	}

	public static boolean putValue(String key, int intValue) {
		editor.putInt(key, intValue);
		editor.commit();
		return true;
	}

	public static int getInt(String key) {
		return sharedPreferences.getInt(key, -1);

	}

	public static boolean putValue(String key, Long longValue) {
		editor.putLong(key, longValue);
		editor.commit();
		return true;
	}

	public static long getLong(String key) {
		return sharedPreferences.getLong(key, -1);
	}

	public static boolean putValue(String key, Set<String> stringSetValue) {
		editor.putStringSet(key, stringSetValue);
		editor.commit();
		return true;
	}

	public static Set<String> getStringSet(String key) {
		return sharedPreferences.getStringSet(key, null);
	}

	public static boolean deleteValue(String key) {
		if (sharedPreferences.contains(key)) {
			editor.remove(key);
			return true;
		}
		return false;
	}

}
